package com.moguhoutai.biz;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.moguhoutai.dao.CityMapper;
import com.moguhoutai.dao.SubwayMapper;
import com.moguhoutai.model.Subway;
import com.moguhoutai.util.BusinessException;

@Service
public class SubwayBiz {
    @Resource
	private SubwayMapper sMapperdao;
    
    @Resource
    private CityMapper cMapperdao;
    
    public Subway findById(int subwayId)throws BusinessException{
    	try {
    		return sMapperdao.selectByPrimaryKey(subwayId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E08B05");
		}
    }
    
    public void save(Subway subway)throws BusinessException{
    	try {
    		    sMapperdao.insert(subway);
    		    cMapperdao.insert(subway.getCity());
    		    
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E08B05");
		}
    }
    
    
    public List<Subway> findSuBycity(int cityId) throws BusinessException  {
  		try {
  		  return sMapperdao.findSuBycity(cityId);
  		} catch (Exception e) {
  			e.printStackTrace();
  			throw new BusinessException("E06B07");
  			
  		}
    }
    
}
